home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / misc / edu / WhirlDisc.lha / WhirlDisc / Source / index_record.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-10  |  2.8 KB  |  130 lines

  1. /*
  2.  
  3. File: index_record.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2000 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24. #include "viewer.h"
  25. #include <exec/memory.h>
  26.  
  27. #include "index_record_protos.h"
  28. #include "reference_protos.h"
  29. #include "general_protos.h"
  30. #include <clib/exec_protos.h>
  31.  
  32.  
  33. /* Function: CreateIndexRecord
  34.  * ===========================
  35.  * Creates an index record.
  36.  */
  37.  
  38. IndexRecord CreateIndexRecord(UBYTE *data)
  39. {
  40.    IndexRecord index_rec;
  41.    BOOL success=TRUE;
  42.    UBYTE *p;
  43.    UWORD i;
  44.    Reference ref;
  45.  
  46.    index_rec=AllocMem(sizeof(IndexRecord_imp),MEMF_CLEAR|MEMF_PUBLIC);
  47.  
  48.    if(index_rec)
  49.    {
  50.       index_rec->data_length=GetLittleEndianUWord(data);
  51.       index_rec->ref_count=*(data+5);
  52.  
  53.       NewList((struct List *)&index_rec->ref_list);
  54.  
  55.       index_rec->data=AllocMem(index_rec->data_length,MEMF_PUBLIC);
  56.  
  57.       if(index_rec->data)
  58.       {
  59.  
  60.          /* Copy record data and store parameters */
  61.  
  62.          CopyMem(data,index_rec->data,index_rec->data_length);
  63.  
  64.          p=index_rec->data+10;
  65.          index_rec->keywords=p;
  66.          p+=strlen(p)+1;
  67.          index_rec->title=p;
  68.          index_rec->node.ln_Name=p;
  69.          p+=strlen(p)+1;
  70.  
  71.          /* Create references from raw data */
  72.  
  73.          for(i=0;i<index_rec->ref_count;i++)
  74.          {
  75.             ref=CreateReference(p);
  76.             if(ref!=NULL)
  77.                AddTail((struct List *)&index_rec->ref_list,&ref->node);
  78.             else
  79.                success=FALSE;
  80.             p+=10;
  81.             while(*(p++)!='\0');
  82.          }
  83.  
  84.       }
  85.       else
  86.       {
  87.          ReportError(NULL,ERROR_REPORT_MEM,NULL,0);
  88.          success=FALSE;
  89.       }
  90.  
  91.       if(!success)
  92.       {
  93.          KillIndexRecord(index_rec);
  94.          index_rec=NULL;
  95.       }
  96.    }
  97.    else
  98.    {
  99.       ReportError(NULL,ERROR_REPORT_MEM,NULL,0);
  100.    }
  101.  
  102. /*printf("index_rec->title=%s\n",index_rec->title);*/
  103.    return index_rec;
  104. }
  105.  
  106.  
  107.  
  108. /* Function: KillIndexRecord
  109.  * =========================
  110.  * Destroys an index record.
  111.  */
  112.  
  113. VOID KillIndexRecord(IndexRecord index_rec)
  114. {
  115.    Reference ref;
  116.  
  117.    while(ref=(Reference)RemHead((struct List *)&index_rec->ref_list))
  118.       KillReference(ref);
  119.  
  120.    if(index_rec->data)
  121.       FreeMem(index_rec->data,index_rec->data_length);
  122.  
  123.    FreeMem(index_rec,sizeof(IndexRecord_imp));
  124.  
  125.    return;
  126. }
  127.  
  128.  
  129.  
  130.